const { ObjectId } = require('mongodb')
const UserModel = require('../../model')
// const Fn = require('../../model')
exports.getUserInfo = (req, res) => {
  const id = req.query.id
  const _id = req.user._id
  if (id) {
    const filter = {
      username: id
    }
    find(filter)
  } else {
    const filter = {
      _id: _id
    }
    find(filter)
  }
  // const id = ObjectId(req.query.id)
  function find(filter) {
    UserModel.Modal.find(filter).lean().exec((err, results) => {
      if (err) return res.cc(err)
      if (results.length !== 1) return res.cc('获取用户信息失败')
      results[0].password = ''
      res.send({
        status: 0,
        messgae: '获取用户信息成功',
        data: results[0]
      })
    })
  }
}

exports.updateUserInfo = (req, res) => {
  const userInfo = req.body
  res.send(userInfo)
  UserModel.Modal.findByIdAndUpdate({ _id: userInfo._id }, { ...userInfo }, { new: true }, (err, results) => {
    console.log(results, 'results');
  })
}

